import 'package:eh_mobile/common/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';

import '../../../../common/values/svg_image.dart';
import '../../common_control/common_control_utils.dart';
import 'light_control_bar.dart';

// 灯光亮度调节页面
class LightBrightnessControlWidget extends StatefulWidget {
  final double brightnessValue;
  final ProgressBarCallback valueDidChanged; // 滑动数值变动返回
  final ProgressBarCallback valueChangedDidEnd; // 滑动结束回调

  const LightBrightnessControlWidget(
      {super.key,
      this.brightnessValue = 0.5,
      required this.valueDidChanged,
      required this.valueChangedDidEnd});

  @override
  State<StatefulWidget> createState() {
    return LightBrightnessControlWidgetState();
  }
}

class LightBrightnessControlWidgetState
    extends State<LightBrightnessControlWidget> {
  late double _brightnessValue = widget.brightnessValue;
  bool _lightOpen = true;

  @override
  Widget build(BuildContext context) {
    return _buildCenterLightControlGridViewItem();
  }

  // 灯光遥控器区域
  Widget _buildCenterLightControlGridViewItem() {
    return Container(
      padding:
          EdgeInsets.only(left: 18.r, right: 18.r, top: 18.h, bottom: 10.h),
      child: Column(
        children: [
          CommonControlUtils.percentView(SVGImage.icBrightnessValueSvg,_brightnessValue),
          30.sizedBoxHeight,
          Expanded(
            child: IgnorePointer(
              ignoring: !_lightOpen,
              child: LightControlBar(
                value: _lightOpen ? _brightnessValue : 0,
                iconName: SVGImage.icBrightnessSvg,
                valueDidChanged: (double value) {
                  setState(() {
                    _brightnessValue = value;
                  });
                  widget.valueDidChanged(_brightnessValue);
                },
                valueChangedDidEnd: (double value) {},
              ),
            ),
          ),
          34.sizedBoxHeight,
          Container(
            decoration: BoxDecoration(
              color: _lightOpen
                  ? const Color.fromRGBO(0, 150, 208, 1)
                  : const Color.fromRGBO(59, 59, 59, 1),
              borderRadius: BorderRadius.circular(26.r),
            ),
            width: 52.r,
            height: 52.r,
            child: IconButton(
                onPressed: () {
                  setState(() {
                    _lightOpen = !_lightOpen;
                  });
                },
                icon: SvgPicture.asset(
                  SVGImage.icPowerOnSvg,
                  colorFilter: ColorFilter.mode(_lightOpen
                      ? const Color.fromRGBO(238, 238, 238, 1)
                      : const Color.fromRGBO(196, 196, 196, 0.5), BlendMode.srcIn),),),
          )
        ],
      ),
    );
  }
}
